#! /usr/bin/env python
# -*- coding: iso-8859-1 -*-
##############################################################################
#
#
#         ___           ___           ___           ___
#        /  /\         /  /\         /  /\         /  /\
#       /  /::\       /  /:/_       /  /:/_       /  /::\
#      /  /:/\:\     /  /:/ /\     /  /:/ /\     /  /:/\:\
#     /  /:/~/:/    /  /:/ /:/_   /  /:/ /::\   /  /:/~/:/
#    /__/:/ /:/___ /__/:/ /:/ /\ /__/:/ /:/\:\ /__/:/ /:/
#    \  \:\/:::::/ \  \:\/:/ /:/ \  \:\/:/~/:/ \  \:\/:/
#     \  \::/~~~~   \  \::/ /:/   \  \::/ /:/   \  \::/
#      \  \:\        \  \:\/:/     \__\/ /:/     \  \:\
#       \  \:\        \  \::/        /__/:/       \  \:\
#        \__\/         \__\/         \__\/         \__\/
#
#
#
#
#   This file is part of ReSP.
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#
#
#   (c) Giovanni Beltrame, Luca Fossati
#       Giovanni.Beltrame@esa.int fossati@elet.polimi.it
#
##############################################################################


import Options

def build(bld):
    # Generation of the controller library
    obj = bld.new_task_gen('cxx', 'cshlib', 'pyembed')
    obj.source ='''
        concurrency_manager.cpp concurrency_emulator.cpp concurrency_structures.cpp
    '''

    obj.target = 'cm'
    obj.uselib = 'SYSTEMC_H BOOST TRAP'
    obj.uselib_local = 'systemc BFDWrapper'

    # Generation of the controller wrapper extension
    obj = bld.new_task_gen('pypp')
    obj.source ='''
        concurrency_manager.hpp concurrency_emulator.hpp
    '''
     
    obj.target = 'cm_wrapper'
    obj.uselib = 'SYSTEMC_H BOOST BOOST_PYTHON TRAP'
    obj.uselib_local = 'systemc BFDWrapper cm'
    obj.start_decls = 'resp'
    obj.custom_code = """
ConcurrencyManager = mb.global_ns.class_('ConcurrencyManager')
ConcurrencyManager.include()
#for attrName in ['busyWaitLoop', 'threadStackSize', 'defThreadInfo', 'interruptServiceRoutines', 'tlsSize', 'tlsData', 'defaultAttr', #'schedLatency', 'deSchedLatency', 'schedChooseLatency']:
#    ConcurrencyManager.variable(attrName).exclude()
#ConcurrencyManager.member_functions().exclude()
mb.global_ns.class_('SysCLock').exclude()
mb.global_ns.class_('ThreadEmu').exclude()
mb.global_ns.class_('AttributeEmu').exclude()
ocls = mb.global_ns.classes(lambda decl: decl.name.startswith('ConcurrencyEmulator'), allow_empty=True)
for i in ocls:
    i.include()
    if i.name == 'ConcurrencyEmulator<unsigned int>':
        i.alias = 'ConcurrencyEmulator32'
"""
    obj.templates = [
        'resp::ConcurrencyEmulator<unsigned int>'
    ]
